# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=glib-networking
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.64.3
pkgrel=1
pkgdesc="Network-related GIO modules for glib (mingw-w64)"
arch=(any)
url="https://gitlab.gnome.org/GNOME/glib-networking"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-libproxy"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-gsettings-desktop-schemas")
replaces=("${MINGW_PACKAGE_PREFIX}-glib-openssl")
conflicts=("${MINGW_PACKAGE_PREFIX}-glib-openssl")
options=('staticlibs' 'strip')
source=("https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz")
sha256sums=('937a06b124052813bfc0b0b86bff42016ff01067582e1aca65bb6dbe0845a168')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  ${MINGW_PREFIX}/bin/meson \
    --buildtype plain \
    --auto-features=enabled \
    -Dopenssl=enabled \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR=${pkgdir}${MINGW_PREFIX} ninja install
  rm -f ${pkgdir}${MINGW_PREFIX}/lib/gio/modules/*.a
# Remove non-applicable systemd files
  rm -rf ${pkgdir}${MINGW_PREFIX}/lib/systemd

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  sed -e "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" \
    -i ${pkgdir}${MINGW_PREFIX}/share/dbus-1/services/org.gtk.GLib.PACRunner.service
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
